package proxy;


import net.sf.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;
import java.util.logging.Logger;

public class IntermediaryMethodInterceptor implements MethodInterceptor {

    private Logger logger = Logger.getLogger(IntermediaryMethodInterceptor.class.getName());

//    @Override
//    public Object invoke(MethodInvocation invocation) throws Throwable {
//        return null;
//    }

    @Override
    public Object intercept(Object o, Method method, Object[] objects, net.sf.cglib.proxy.MethodProxy methodProxy) throws Throwable {
        before();
        Object feedback = methodProxy.invokeSuper(o, objects);
        after();
        return "看房记录:买家反馈 “"+feedback+"”";
    }


    private void after() {
        logger.info("后期跟踪");
        logger.info("和卖家沟通时间");
    }

    private void before() {
        logger.info("前期准备。");
        logger.info("查找房源");
        logger.info("和卖家沟通时间。");
    }
}
